<template>
    <div
      class="wrapper"
      :style="{position:'fixed',top:position.y +'px',left:position.x+'px'}">
      <div v-if="!mockList.length" class="empty">无搜索结果</div>
      <ul v-infinite-scroll="load" class="infinite-list" style="overflow: auto;font-size: 14px;">
        <li v-for="item,i in mockList" :key="item.id" class="item"  ref="usersRef"
        @click="clickAt($event,item)"
        @mouseenter="hoverAt(i)"
        :class="{'active': i === index}"><span>{{ item.groupUserName }}</span></li>
      </ul>
    </div>
    </template>
     
    <script>
    import request from '@/utils/request'
    export default {
      props: {
        visible: Boolean,
        position: Object,
        queryString: String,
        wcid: String,
        groupid: String,
      },
      data () {
        return {
          total:null,
          users: [],
          index: -1,
          mockList: [],
          mockData:[],
          userParams:{
            pageNum: 1,
            pageSize: 10,
            wcId: null,
            wcGroupId: null,
          },
        }
      },
      watch: {
        queryString (val) {
          val ? this.mockList = this.mockData.filter(({ name }) => name.startsWith(val)) : this.mockList = this.mockData.slice(0)
        },
      },
      mounted () {
        this.getUser()
        
      },
      destroyed () {
        
      },
      methods: {
        getUser(){
          this.userParams.wcId = this.wxid;
          this.userParams.wcGroupId = this.groupid;
          getUser(this.userParams).then(res => {
            //console.log(res)
            if (res['code']==200) {
              const dt = res['data'];
              this.total = dt['total'];
              this.mockData = [...this.mockData,...dt['records']];
              this.mockList =this.mockData
            }
          });
        },
        load(){
          if(this.total==this.userParams.pageSize){
            this.userParams.pageNum+=1
            this.getUser()
          }
        },
        clickAt (e, item) {
          this.$emit('onPickUser', item)
          this.index = -1
        },
        hoverAt (index) {
          this.index = index
        }
      }
    }
    //获取群成员
    export function getUser(query) {
       return request({
         url: '/arbit/wcgroups_user/page',
         method: 'get',
         params:query
       })
    }
    </script>
     
    <style scoped lang="scss">
      .wrapper {
        width: 160px;
        max-height: 160px;
        border: 1px solid #e4e7ed;
        border-radius: 4px;
        background-color: #fff;
        box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
        box-sizing: border-box;
        padding: 6px 0;
        margin-top: -150px;
        z-index: 999;
      }
      .infinite-list {
        height: 140px;
        padding: 0;
        margin: 0;
        list-style: none;
      }
      .infinite-list .infinite-list-item {
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--el-color-primary-light-9);
        margin: 10px;
        color: var(--el-color-primary);
      }
      .infinite-list .infinite-list-item + .list-item {
        margin-top: 10px;
      }
      .empty{
        font-size: 14px;
        padding: 0 20px;
        color: #999;
      }
      .item {
        font-size: 14px;
        padding: 0 20px;
        line-height: 34px;
        cursor: pointer;
        color: #606266;
        &.active {
          background: #f5f7fa;
          color: blue;
          .id {
            color: blue;
          }
        }
        &:first-child {
          border-radius: 5px 5px 0 0;
        }
        &:last-child {
          border-radius: 0 0 5px 5px;
        }
        .id {
          font-size: 12px;
          color: rgb(83, 81, 81);
        }
      }
    </style>